package com.jiayang.hhotel.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.adapter.HomeMenuAdapter;
import com.jiayang.hhotel.bean.LoginModel;
import com.jiayang.hhotel.presenter.FrontFragmentPresenter;
import com.jiayang.hhotel.ui.AgreeGuestActivity;
import com.jiayang.hhotel.ui.BookDinnerSearchActivity;
import com.jiayang.hhotel.ui.CanRentRoomActivity;
import com.jiayang.hhotel.ui.CleanActivity;
import com.jiayang.hhotel.ui.FinanceHandleActivity;
import com.jiayang.hhotel.ui.NewestStatisticsActivity;
import com.jiayang.hhotel.ui.NightAuditActivity;
import com.jiayang.hhotel.ui.NowLiveSearchActivity;
import com.jiayang.hhotel.ui.ReservationSearchActivity;
import com.jiayang.hhotel.ui.RoundsActivity;
import com.jiayang.hhotel.ui.SettingMenuActivity;
import com.jiayang.hhotel.ui.SpecialRoomStateActivity;
import com.jiayang.hhotel.ui.StatisticalActivity;
import com.jiayang.hhotel.ui.StatisticsAnalysisListActivity;
import com.jiayang.hhotel.util.GlideImageLoader;
import com.jiayang.hhotel.view.CanNestingGirdView;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import cn.droidlover.xdroidmvp.mvp.XLazyFragment;

/**
 * Created by Administrator on 2017/5/22 0022.
 * 首页
 */

public class FrontFragment extends XLazyFragment<FrontFragmentPresenter> implements HomeMenuAdapter.OnItemClickListener {

    private CanNestingGirdView gridLayout;
    private HomeMenuAdapter adapter;
    private Intent intent;

    @Override
    public void initData(Bundle savedInstanceState) {

        LayoutInflater minflater=LayoutInflater.from(getActivity());

        TextView title= (TextView) getRootView().findViewById(R.id.tv_title);
        ImageView message= (ImageView) getRootView().findViewById(R.id.iv_message);
        Banner banner = (Banner) getRootView().findViewById(R.id.banner);
        LinearLayout ll_gallay=(LinearLayout)getRootView().findViewById(R.id.id_gallery);

        gridLayout=(CanNestingGirdView) getRootView().findViewById(R.id.menu_parent);
        title.setText("xx酒店");

        String[] texts=getActivity().getResources().getStringArray(R.array.home_policy_text_list);
        Integer[] imgs=new Integer[]{R.mipmap.hotel_culture,R.mipmap.foreign_policy,R.mipmap.room_role,R.mipmap.favourable,R.mipmap.feature,R.mipmap.installation,R.mipmap.hotel_item};

        //设置政策宣传的图片
        for(int i=0;i<7;i++){
            View itemView = minflater.inflate(R.layout.index_gallery_item,
                    ll_gallay, false);
            ImageView img = (ImageView) itemView
                    .findViewById(R.id.id_index_gallery_item_image);
            img.setImageResource(imgs[i]);
            TextView txt = (TextView) itemView
                    .findViewById(R.id.id_index_gallery_item_text);
            txt.setText(texts[i]);
            ll_gallay.addView(itemView);
        }

        message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        //设置图片加载器
        banner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        List<Integer> imgList = new ArrayList<>();//此处可以放置图片的网络路径
        imgList.add(R.drawable.banners);
        imgList.add(R.drawable.banners);
        imgList.add(R.drawable.banners);
        imgList.add(R.drawable.banners);
        imgList.add(R.drawable.banners);
        imgList.add(R.drawable.banners);
        imgList.add(R.drawable.banners);
        banner.setImages(imgList);
        //banner设置方法全部调用完毕时最后调用
        banner.start();
        getP().getJurisdictionList();
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_index;
    }

    @Override
    public FrontFragmentPresenter newP() {
        return new FrontFragmentPresenter();
    }

    public void setAdapter(List<LoginModel.LoginBean.PRightIdDtolistBean> list){
        if(adapter==null){
            adapter=new HomeMenuAdapter(getActivity(),list,this);
            gridLayout.setAdapter(adapter);
        }else{
            adapter.notifyDataSetChanged();
        }
    }

    /**
     * 菜单item点击监听
     * @param id 权限值 用于点击的id
     */
    @Override
    public void OnItemClick(String id) {
        switch (id){
            case "020801"://订房查询
                intent=new Intent(getActivity(), ReservationSearchActivity.class);
                startActivity(intent);
                break;
            case "020803"://订餐查询
                intent=new Intent(getActivity(), BookDinnerSearchActivity.class);
                startActivity(intent);
                break;
            case "1402"://可租房
                intent=new Intent(getActivity(), CanRentRoomActivity.class);
                startActivity(intent);
                break;
            case "1401"://最新统计
                intent=new Intent(getActivity(), NewestStatisticsActivity.class);
                startActivity(intent);
                break;
            case "0301"://现住查询
                intent=new Intent(getActivity(), NowLiveSearchActivity.class);
                startActivity(intent);
                break;
            case "0401"://查房
                intent=new Intent(getActivity(), RoundsActivity.class);
                startActivity(intent);
                break;
            case "0402"://清洁
                intent=new Intent(getActivity(), CleanActivity.class);
                startActivity(intent);
                break;
            case "0411"://特殊房态
                intent=new Intent(getActivity(), SpecialRoomStateActivity.class);
                startActivity(intent);
                break;
            case "06"://财务处理
                intent=new Intent(getActivity(), FinanceHandleActivity.class);
                startActivity(intent);
                break;
            case "16"://夜审
                intent=new Intent(getActivity(), NightAuditActivity.class);
                startActivity(intent);
                break;
            case "0105"://统计分析
                intent=new Intent(getActivity(), StatisticsAnalysisListActivity.class);
                startActivity(intent);
                break;
            case "0106"://协议客户
                intent=new Intent(getActivity(), AgreeGuestActivity.class);
                startActivity(intent);
                break;
            case "15"://设置
                intent=new Intent(getActivity(), SettingMenuActivity.class);
                startActivity(intent);
                break;
        }
    }
}
